#!/usr/bin/env python

import os
from google.appengine.ext.webapp import template
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import util

class MainHandler(webapp.RequestHandler):
    def get(self):
        if(users.get_current_user() != None):
            self.redirect("/Explorer/")
        template_values = { 'page_title' : 'v.01Alpha '}
            

        path = os.path.join(os.path.dirname(__file__), 'templates/Index.html')
        self.response.out.write(template.render(path, template_values))

class SignOut(webapp.RequestHandler):
    def get(self):
        
        if(users.get_current_user() == None):
            self.redirect("/")
        else:
            self.redirect(users.CreateLogoutURL("/"))

def main():
    application = webapp.WSGIApplication([('/', MainHandler),
                                            ('/SignOut', SignOut),
                                            ],
                                         debug=True)
    util.run_wsgi_app(application)


if __name__ == '__main__':
    main()
